﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Code.Manufacture;
using Code.ProductType;
using E2_WEBSITE.Code.Product;
using System.Data;
using E2_WEBSITE.Code;
using E2_WEBSITE.Code.CPU;
using E2_WEBSITE.Code.RAM;
using E2_WEBSITE.Code.HDD;
using E2_WEBSITE.Code.CASE;
using E2_WEBSITE.Code.CD_DVD;
using E2_WEBSITE.Code.SOUNDCARD;
using E2_WEBSITE.Code.POWER;
using E2_WEBSITE.Code.VGA;
using E2_WEBSITE.Code.HINH_ANH;

public partial class Products_customize : System.Web.UI.Page
{

    private void UpdateTotalPrice()
    {
        int iTotal = 0;
        HinhAnhController hacl = new HinhAnhController();
        int iNum = 0;
        string strPara = string.Empty;
        btnAddToCart.PostBackUrl = "";
        if(lbMainPrice.Text != "")
        {
            iNum++;
            ProductController pcl = new ProductController();
            int iMainProId = pcl.GetProductIdByProductNameAndCatelogyAndManufacture(cbMainProduct.Text, cbMainManufacture.Text, "MAINBOARD");
            int iImageId = hacl.GetHinhAnhIDByColorNameAndProductName(cbMainColor.Text, cbMainProduct.Text);
            strPara += "&pID" + iNum.ToString() + "=" + iMainProId.ToString() + "&cID" + iNum.ToString() + "=" + iImageId.ToString() + "&quan" + iNum.ToString() + "=1";
            iTotal += Utilities.ParseVNDMoneyFormatToValue(lbMainPrice.Text);
        }
        if (lbCPUPrice.Text != "")
        {
            iNum++;
            CPUController ccl = new CPUController();
            int iID = ccl.GetCPUIDByManuAndsocketAndBusAndSpeedAndName(cbCPUManufacture.Text, cbCPUSocket.Text, cbCPUBus.Text, cbCPUSpeed.Text, cbCPUProduct.Text);
            int iImageId = hacl.GetHinhAnhIDByColorNameAndProductName(cbCPUColor.Text, cbCPUProduct.Text);
            strPara += "&pID" + iNum.ToString() + "=" + iID.ToString() + "&cID" + iNum.ToString() + "=" + iImageId.ToString() + "&quan" + iNum.ToString() + "=1";

            iTotal += Utilities.ParseVNDMoneyFormatToValue(lbCPUPrice.Text);
        }
        if (lbRamPrice.Text != "")
        {
            iNum++;
            RamController rcl = new RamController();
            int iID = rcl.GetRamIDByManufactureAndBusAndMemoryAndName(cbRAMManufacture.Text, cbRAMBus.Text, cbRAMMemory.Text, cbRAMProduct.Text); 
            int iImageId = hacl.GetHinhAnhIDByColorNameAndProductName(cbRAMColor.Text, cbRAMProduct.Text);
            strPara += "&pID" + iNum.ToString() + "=" + iID.ToString() + "&cID" + iNum.ToString() + "=" + iImageId.ToString() + "&quan" + iNum.ToString() + "=1";
            iTotal += Utilities.ParseVNDMoneyFormatToValue(lbRamPrice.Text);
        }
        if (lbCDPrice.Text != "")
        {
            iNum++;
            CDController ccl = new CDController();
            int iID = ccl.GetCDIDByManuAndSpeedAndName(cbCDManufacture.Text, cbCDSpeed.Text, cbCDProduct.Text);
            int iImageId = hacl.GetHinhAnhIDByColorNameAndProductName(cbCDColor.Text, cbCDProduct.Text);
            strPara += "&pID" + iNum.ToString() + "=" + iID.ToString() + "&cID" + iNum.ToString() + "=" + iImageId.ToString() + "&quan" + iNum.ToString() + "=1";
            iTotal += Utilities.ParseVNDMoneyFormatToValue(lbCDPrice.Text);
        }
        if (lbHDDPrice.Text != "")
        {
            iNum++;
            HDDController hcl = new HDDController();
            int iID = hcl.GetHDDIdByManuAndMemoryAndStandardAndRoundAndName(cbHDDManufacture.Text, cbHDDMemory.Text, cbHDDStandard.Text, cbHDDRound.Text, cbHDDProduct.Text);
            int iImageId = hacl.GetHinhAnhIDByColorNameAndProductName(cbHDDColor.Text, cbHDDProduct.Text);
            strPara += "&pID" + iNum.ToString() + "=" + iID.ToString() + "&cID" + iNum.ToString() + "=" + iImageId.ToString() + "&quan" + iNum.ToString() + "=1";
 
            iTotal += Utilities.ParseVNDMoneyFormatToValue(lbHDDPrice.Text);
        }
        if (lbCasePrice.Text != "")
        {
            iNum++;
            CaseController ccl = new CaseController();
            int iID = ccl.GetProIDByManuAndProName(cbCASEManufacture.Text, cbCASEProduct.Text);
            int iImageId = hacl.GetHinhAnhIDByColorNameAndProductName(cbCaseColor.Text, cbCASEProduct.Text);
            strPara += "&pID" + iNum.ToString() + "=" + iID.ToString() + "&cID" + iNum.ToString() + "=" + iImageId.ToString() + "&quan" + iNum.ToString() + "=1";
 
            iTotal += Utilities.ParseVNDMoneyFormatToValue(lbCasePrice.Text);
        }
        if (lbPowerPrice.Text != "")
        {
            iNum++;
            PowerController ccl = new PowerController();
            int iID = ccl.GetProIDByManuAndProName(cbPOWERManufacture.Text, cbPOWERProduct.Text);
            int iImageId = hacl.GetHinhAnhIDByColorNameAndProductName(cbPowerColor.Text, cbPOWERProduct.Text);
            strPara += "&pID" + iNum.ToString() + "=" + iID.ToString() + "&cID" + iNum.ToString() + "=" + iImageId.ToString() + "&quan" + iNum.ToString() + "=1";
 
            iTotal += Utilities.ParseVNDMoneyFormatToValue(lbPowerPrice.Text);
        }
        if (lbSoundCardPrice.Text != "")
        {
            iNum++;
            SoundCardController ccl = new SoundCardController();
            int iID = ccl.GetProIDByManuAndProName(cbSOUNDCARDManufacture.Text, cbSOUNDCARDProduct.Text);
            int iImageId = hacl.GetHinhAnhIDByColorNameAndProductName(cbSoundCardColor.Text, cbSOUNDCARDProduct.Text);
            strPara += "&pID" + iNum.ToString() + "=" + iID.ToString() + "&cID" + iNum.ToString() + "=" + iImageId.ToString() + "&quan" + iNum.ToString() + "=1";
 
            iTotal += Utilities.ParseVNDMoneyFormatToValue(lbSoundCardPrice.Text);
        }
        if (lbVGAPrice.Text != "")
        {
            iNum++;
            VGAController vcl = new VGAController();
            int iID = vcl.GetVGAIDByManufactureAndEngineAndMemoryAndName(cbVGAManufacture.Text, cbVGAEngine.Text, cbVGAMemory.Text, cbVGAProduct.Text);
            int iImageId = hacl.GetHinhAnhIDByColorNameAndProductName(cbVGAColor.Text, cbVGAColor.Text);
            strPara += "&pID" + iNum.ToString() + "=" + iID.ToString() + "&cID" + iNum.ToString() + "=" + iImageId.ToString() + "&quan" + iNum.ToString() + "=1";

            iTotal += Utilities.ParseVNDMoneyFormatToValue(lbVGAPrice.Text);
        }
        if(iNum > 0)
        {
            strPara = "num="+iNum.ToString() +strPara;
            btnAddToCart.PostBackUrl = "~//cp//member//addtocart.aspx?" + strPara;
        }
        lbTotalPrice.Text = Utilities.ConvertToMoneyFormat(iTotal,true);
    }

    private void MainBoardPostBackProcessing()
    {
        bool bChild = false;
        //Main Board Processing
        lbMainPrice.Text = "";
        if (tbMainImageRow.Cells[1].Controls.Count > 0)
        {
            tbMainImageRow.Cells[1].Controls.RemoveAt(0);
        }
        if (cbMainManufacture.SelectedIndex > 0)
        {

            bChild = false;
            ProductController pcl = new ProductController();
            List<string> lsMainPro = pcl.GetListProductNameByManufactureNameAndCatelogyName(cbMainManufacture.Text, "MAINBOARD");
            if (cbMainProduct.Enabled == true)
            {
                if (lsMainPro.Contains(cbMainProduct.Text))
                {
                    bChild = true;
                }
            }
            else
                cbMainProduct.Enabled = true;
            if (!bChild)
            {
                cbMainProduct.Items.Clear();
                cbMainProduct.Items.Add("- Chọn Sản Phẩm -");
                foreach (string str in lsMainPro)
                {
                    cbMainProduct.Items.Add(str);
                }
                lbMainPrice.Text = "";
                cbMainColor.SelectedIndex = 0;
                cbMainColor.Enabled = false;
            }
            else
            {
                bChild = false;
                HinhAnhController hcl = new HinhAnhController();
                List<string> lstColor = hcl.GetListColorByProName(cbMainProduct.Text);
                if(cbMainColor.Enabled && cbMainColor.SelectedIndex > 0)
                {
                    if(lstColor.Contains(cbMainColor.Text))
                    {
                        bChild = true;
                    }
                }
                if(!bChild)
                {
                    cbMainColor.Enabled = true;
                    cbMainColor.Items.Clear();
                    cbMainColor.Items.Add("- Chọn Màu Sắc -");
                    foreach (string str in lstColor)
                    {
                        cbMainColor.Items.Add(str);
                    }
                }
                else
                {
                    ProductTypeController ptcl = new ProductTypeController();
                    int iMainCatelogyID = ptcl.GetProductTypeIDByName("MAINBOARD");
                    int iMainProId = pcl.GetProductIdByProductNameAndCatelogyAndManufacture(cbMainProduct.Text, cbMainManufacture.Text, "MAINBOARD");
                    DataTable dtMain;
                    //ProductInfo pMainInfo = pcl.getProductById(iMainProId);
                    ProductInfo pMainInfoDetail = pcl.getProductDetail(iMainProId.ToString(), "MAINBOARD", out dtMain);
                    HyperLink imgMainboard = new HyperLink();
                    imgMainboard.ImageUrl = pMainInfoDetail.Hinh_Anh.URL;
                    imgMainboard.NavigateUrl = "~/Products/detail.aspx?ProductId=" + iMainProId.ToString() + "&CategoryId=" + iMainCatelogyID.ToString();
                    tbMainImageRow.Cells[1].Controls.Add(imgMainboard);
                    lbMainPrice.Text = Utilities.ConvertToMoneyFormat(pMainInfoDetail.Gia, true);
                    UpdateTotalPrice();
                }
                //Load hinh
               
            }

        }
        else
        {
            cbMainManufacture.SelectedIndex = 0;
            cbMainProduct.SelectedIndex = 0;
            cbMainProduct.Enabled = false;
            cbMainColor.SelectedIndex = 0;
            cbMainColor.Enabled = false;
          
        }
    }

    private void CPUPostBackProcessing()
    {
        bool bChild = false;
        //CPU Processing
        lbCPUPrice.Text = "";
        if(tbImgCPU.Cells[1].Controls.Count >0)
        {
            tbImgCPU.Cells[1].Controls.RemoveAt(0);
        }

        if (cbCPUManufacture.SelectedIndex > 0)
        {
            bChild = false;

            CPUController ccl = new CPUController();
            List<string> lstSocket = ccl.GetListSocketByManufactureName(cbCPUManufacture.Text);

            //Socket Check Child
            if (cbCPUSocket.Enabled && cbCPUSocket.SelectedIndex > 0)
            {
                if (lstSocket.Contains(cbCPUSocket.Text))
                {
                    bChild = true;
                }
            }

            if (!bChild)
            {
                cbCPUSocket.Enabled = true;
                cbCPUSocket.Items.Clear();
                cbCPUSocket.Items.Add("- Chọn Socket -");
                foreach (string str in lstSocket)
                {
                    cbCPUSocket.Items.Add(str);
                }
                cbCPUSpeed.Items.Clear();
                cbCPUBus.Items.Clear();
                cbCPUProduct.Items.Clear();
                cbCPUBus.Items.Add("- Chọn Bus -");
                cbCPUSpeed.Items.Add("- Chọn Tốc Độ -");
                cbCPUProduct.Items.Add("- Chọn Sản Phẩm -");
                cbCPUBus.Enabled = false;
                cbCPUSpeed.Enabled = false;
                cbCPUProduct.Enabled = false;
                cbCPUColor.SelectedIndex = 0;
                cbCPUColor.Enabled = false;
               
            }
            else
            {
                //Bus Check Child
                bChild = false;
                List<string> lstBus = ccl.GetListBusByManufactureNameAndSocket(cbCPUManufacture.Text, cbCPUSocket.Text);
                if (cbCPUBus.Enabled && cbCPUBus.SelectedIndex > 0)
                {
                    if (lstBus.Contains(cbCPUBus.Text))
                    {
                        bChild = true;
                    }
                }

                if (!bChild)
                {
                    cbCPUBus.Enabled = true;
                    cbCPUBus.Items.Clear();
                    cbCPUBus.Items.Add("- Chọn Bus -");
                    foreach (string str in lstBus)
                    {
                        cbCPUBus.Items.Add(str);
                    }
                    cbCPUSpeed.Items.Clear();
                    cbCPUProduct.Items.Clear();
                    cbCPUSpeed.Items.Add("- Chọn Tốc Đô -");
                    cbCPUProduct.Items.Add("- Chọn Sản Phẩm -");
                    cbCPUProduct.Enabled = false;
                    cbCPUSpeed.Enabled = false;
                    cbCPUColor.SelectedIndex = 0;
                    cbCPUColor.Enabled = false;
                }
                else
                {
                    //speed Check Child
                    bChild = false;
                    List<string> lstSpeed = ccl.GetListSpeedByManuAndSocketAndBus(cbCPUManufacture.Text, cbCPUSocket.Text, cbCPUBus.Text);
                    if (cbCPUSpeed.Enabled && cbCPUSpeed.SelectedIndex > 0)
                    {
                        if (lstSpeed.Contains(cbCPUSpeed.Text))
                        {
                            bChild = true;
                        }
                    }

                    if (!bChild)
                    {
                        cbCPUSpeed.Enabled = true;
                        cbCPUSpeed.Items.Clear();
                        cbCPUProduct.Items.Clear();
                        cbCPUSpeed.Items.Add("- Chọn Tốc Đô -");
                        cbCPUProduct.Items.Add("- Chọn Sản Phẩm -");
                        foreach (string str in lstSpeed)
                        {
                            cbCPUSpeed.Items.Add(str);
                        }
                        cbCPUProduct.Enabled = false;
                        cbCPUColor.SelectedIndex = 0;
                        cbCPUColor.Enabled = false;
                    }
                    else
                    {
                        // Check Product Child
                        bChild = false;
                        List<string> lstProduct = ccl.GetListProductNameBuManuAndSocketAndBusAndSpeed(cbCPUManufacture.Text, cbCPUSocket.Text, cbCPUBus.Text, cbCPUSpeed.Text);
                        if (cbCPUProduct.Enabled && cbCPUProduct.SelectedIndex > 0)
                        {
                            if (lstProduct.Contains(cbCPUProduct.Text))
                            {
                                bChild = true;
                            }
                        }

                        if (!bChild)
                        {
                            cbCPUProduct.Enabled = true;
                            cbCPUProduct.Items.Clear();
                            cbCPUProduct.Items.Add("- Chọn Sản Phẩm -");
                            foreach (string str in lstProduct)
                            {
                                cbCPUProduct.Items.Add(str);
                            }
                            cbCPUColor.SelectedIndex = 0;
                            cbCPUColor.Enabled = false;
                        }
                        else
                        {

                            bChild = false;
                            HinhAnhController hcl = new HinhAnhController();
                            List<string> lstColor = hcl.GetListColorByProName(cbCPUProduct.Text);
                            if(cbCPUColor.Enabled && cbCPUColor.SelectedIndex > 0)
                            {
                                if (lstColor.Contains(cbCPUColor.Text))
                                {
                                    bChild = true;
                                }
                            }

                            if(!bChild)
                            {
                                cbCPUColor.Enabled = true;
                                cbCPUColor.Items.Clear();
                                cbCPUColor.Items.Add("- Chọn Màu Sắc -");
                                foreach (string str in lstColor)
                                {
                                    cbCPUColor.Items.Add(str);
                                }
                            }
                            else
                            {
                                ProductTypeController ptcl = new ProductTypeController();
                                int iCPUCatelogyID = ptcl.GetProductTypeIDByName("CPU");
                                int iID = ccl.GetCPUIDByManuAndsocketAndBusAndSpeedAndName(cbCPUManufacture.Text, cbCPUSocket.Text, cbCPUBus.Text, cbCPUSpeed.Text, cbCPUProduct.Text);
                                ProductController pCPUController = new ProductController();
                                DataTable dtCPU;
                                ProductInfo pInfo = pCPUController.getProductDetail(iID.ToString(), iCPUCatelogyID.ToString(), out dtCPU);
                                HyperLink imgCPU = new HyperLink();
                                imgCPU.ImageUrl = pInfo.Hinh_Anh.URL;
                                imgCPU.NavigateUrl = "~/Products/detail.aspx?ProductId=" + iID.ToString() + "&CategoryId=" + iCPUCatelogyID.ToString();
                                tbImgCPU.Cells[1].Controls.Add(imgCPU);
                                lbCPUPrice.Text = Utilities.ConvertToMoneyFormat(pInfo.Gia, true);
                                UpdateTotalPrice();
                            }
                            // Load san pham
                           
                        }

                    }
                }
            }
        }
        else
        {
            cbCPUSocket.SelectedIndex = 0;
            cbCPUSpeed.SelectedIndex = 0;
            cbCPUBus.SelectedIndex = 0;
            cbCPUProduct.SelectedIndex = 0;
            cbCPUProduct.Enabled = false;
            cbCPUSocket.Enabled = false;
            cbCPUSpeed.Enabled = false;
            cbCPUBus.Enabled = false;
            cbCPUColor.SelectedIndex = 0;
            cbCPUColor.Enabled = false;
             
        }
    }

    private void RamPostBackProcessing()
    {
        bool bChild;
        lbRamPrice.Text = "";
        if(tbImgRam.Cells[1].Controls.Count > 0)
        {
            tbImgRam.Cells[1].Controls.RemoveAt(0);
        }
        if(cbRAMManufacture.SelectedIndex > 0)
        {
            bChild = false;
            RamController rcl = new RamController();
            List<string> lstBus = rcl.GetListBusByManufacture(cbRAMManufacture.Text);
            if(cbRAMBus.Enabled && cbRAMBus.SelectedIndex > 0)
            {
                if(lstBus.Contains(cbRAMBus.Text))
                {
                    bChild = true;
                }
            }

            if(!bChild)
            {
                cbRAMBus.Enabled = true;
                cbRAMBus.Items.Clear();
                cbRAMBus.Items.Add("- Chọn Bus -");
                foreach (string str in lstBus)
                {
                    cbRAMBus.Items.Add(str);
                }
                cbRAMMemory.Items.Clear();
                cbRAMProduct.Items.Clear();
                cbRAMMemory.Items.Add("- Chọn Dung Lượng -");
                cbRAMProduct.Items.Add("- Chọn Sản Phẩm -");
                cbRAMMemory.Enabled = false;
                cbRAMProduct.Enabled = false;
                cbRAMColor.SelectedIndex = 0;
                cbRAMColor.Enabled = false;

            }
            else
            {
                // Check Memory
                bChild = false;

                List<string> lstRamMemory = rcl.GetListMemoryByManufactureAndBus(cbRAMManufacture.Text, cbRAMBus.Text);
                if(cbRAMMemory.Enabled && cbRAMMemory.SelectedIndex > 0)
                {
                    if(lstRamMemory.Contains(cbRAMMemory.Text))
                    {
                        bChild = true;
                    }
                }

                if(!bChild)
                {
                    cbRAMMemory.Enabled = true;
                    cbRAMMemory.Items.Clear();
                    cbRAMMemory.Items.Add("- Chọn Dung Lượng -");
                    foreach (string str in lstRamMemory)
                    {
                        cbRAMMemory.Items.Add(str);
                    }
                    cbRAMProduct.Items.Clear();
                    cbRAMProduct.Items.Add("- Chọn Sản Phẩm -");
                    cbRAMProduct.Enabled = false;
                    cbRAMColor.SelectedIndex = 0;
                    cbRAMColor.Enabled = false;
                }
                else
                {
                    List<string> lstRamProduct = rcl.GetListProductByManufactureAndBusAndMemory(cbRAMManufacture.Text, cbRAMBus.Text, cbRAMMemory.Text);
                    bChild = false;
                    if(cbRAMProduct.Enabled && cbRAMProduct.SelectedIndex > 0)
                    {
                       if(lstRamProduct.Contains(cbRAMProduct.Text))
                       {
                           bChild = true;
                       }
                    }

                    if(!bChild)
                    {
                        cbRAMProduct.Enabled = true;
                        cbRAMProduct.Items.Clear();
                        cbRAMProduct.Items.Add("- Chọn Sản Phẩm -");
                        foreach(string str in lstRamProduct)
                        {
                            cbRAMProduct.Items.Add(str);
                        }
                        cbRAMColor.SelectedIndex = 0;
                        cbRAMColor.Enabled = false;

                    }
                    else
                    {
                        bChild = false;
                        HinhAnhController hcl = new HinhAnhController();
                        List<string> lstColor = hcl.GetListColorByProName(cbRAMProduct.Text);
                        if(cbRAMColor.Enabled && cbRAMColor.SelectedIndex > 0)
                        {
                            if(lstColor.Contains(cbRAMColor.Text))
                            {
                                bChild = true;
                            }
                        }
                        if (!bChild)
                        {
                            cbRAMColor.Enabled = true;
                            cbRAMColor.Items.Clear();
                            cbRAMColor.Items.Add("- Chọn Màu Sắc -");
                            foreach (string str in lstColor)
                            {
                                cbRAMColor.Items.Add(str);
                            }
                        }
                        else
                        {
                            //Load san pham RAM
                            int iID = rcl.GetRamIDByManufactureAndBusAndMemoryAndName(cbRAMManufacture.Text, cbRAMBus.Text, cbRAMMemory.Text, cbRAMProduct.Text);
                            ProductTypeController ptcl = new ProductTypeController();
                            int iRAMCateID = ptcl.GetProductTypeIDByName("RAM");
                            ProductController pcl = new ProductController();
                            DataTable dt;
                            ProductInfo pInfo = pcl.getProductDetail(iID.ToString(), iRAMCateID.ToString(), out dt);
                            HyperLink imgRam = new HyperLink();
                            imgRam.ImageUrl = pInfo.Hinh_Anh.URL;
                            imgRam.NavigateUrl = "~/Products/detail.aspx?ProductId=" + iID.ToString() + "&CategoryId=" + iRAMCateID.ToString();
                            tbImgRam.Cells[1].Controls.Add(imgRam);
                            lbRamPrice.Text = Utilities.ConvertToMoneyFormat(pInfo.Gia, true);
                            UpdateTotalPrice();
                        }
                    }
                }
            }

        }
        else
        {
            cbRAMBus.SelectedIndex = 0;
            cbRAMMemory.SelectedIndex = 0;
            cbRAMProduct.SelectedIndex = 0;
            cbRAMProduct.Enabled = false;
            cbRAMMemory.Enabled = false;
            cbRAMBus.Enabled = false;
            cbRAMColor.SelectedIndex = 0;
            cbRAMColor.Enabled = false;

        }
    }

    private void HDDPostBackProcessing()
    {
        bool bChild = false;
        lbHDDPrice.Text = "";
        if(tbimgHDD.Cells[1].Controls.Count > 0)
        {
            tbimgHDD.Cells[1].Controls.RemoveAt(0);
        }
        
        if(cbHDDManufacture.SelectedIndex > 0)
        {
            //Check Memory
            bChild = false;
            HDDController hcl = new HDDController();
            List<string> lsHDDMemory= hcl.GetListMemoryByManufacture(cbHDDManufacture.Text);
            if(cbHDDMemory.Enabled && cbHDDMemory.SelectedIndex > 0)
            {
                if(lsHDDMemory.Contains(cbHDDMemory.Text))
                {
                    bChild = true;
                }
            }

            if(!bChild)
            {
                cbHDDMemory.Enabled = true;
                cbHDDMemory.Items.Clear();
                cbHDDMemory.Items.Add("- Chọn Dung Lượng -");
                foreach (string str in lsHDDMemory)
                {
                    cbHDDMemory.Items.Add(str);
                }
                cbHDDStandard.SelectedIndex = 0;
                cbHDDRound.SelectedIndex = 0;
                cbHDDProduct.SelectedIndex = 0;
                cbHDDStandard.Enabled = false;
                cbHDDRound.Enabled = false;
                cbHDDProduct.Enabled = false;
                cbHDDColor.SelectedIndex = 0;
                cbHDDColor.Enabled = false;
            }
            else
            {
                //Check Standard
                bChild = false;
                List<string> lsHDDStandard = hcl.GetListStandardByManufactureAndMemory(cbHDDManufacture.Text, cbHDDMemory.Text);
                if(cbHDDStandard.Enabled  && cbHDDStandard.SelectedIndex > 0)
                {
                    if(lsHDDStandard.Contains(cbHDDStandard.Text))
                    {
                        bChild = true;
                    }
                }

                if(!bChild)
                {
                    cbHDDStandard.Enabled = true;
                    cbHDDStandard.Items.Clear();
                    cbHDDStandard.Items.Add("- Chọn Chuẩn -");
                    foreach (string str in lsHDDStandard)
                    {
                        cbHDDStandard.Items.Add(str);
                    }

                    cbHDDRound.SelectedIndex = 0;
                    cbHDDRound.Enabled = false;
                    cbHDDProduct.SelectedIndex = 0;
                    cbHDDProduct.Enabled = false;
                    cbHDDColor.SelectedIndex = 0;
                    cbHDDColor.Enabled = false;
                }
                else
                {
                    //Check Round
                    bChild = false;
                    List<string> lsHDDRound = hcl.GetListRoundByManuAndMemoryAndStandard(cbHDDManufacture.Text, cbHDDMemory.Text, cbHDDStandard.Text);
                    if(cbHDDRound.Enabled && cbHDDRound.SelectedIndex > 0)
                    {
                        if(lsHDDRound.Contains(cbHDDRound.Text))
                        {
                            bChild = true;
                        }
                    }

                    if (!bChild)
                    {
                        cbHDDRound.Enabled = true;
                        cbHDDRound.Items.Clear();
                        cbHDDRound.Items.Add("- Chọn Số Vòng -");
                        foreach (string str in lsHDDRound)
                        {
                            cbHDDRound.Items.Add(str);
                        }
                        cbHDDProduct.SelectedIndex = 0;
                        cbHDDProduct.Enabled = false;
                        cbHDDColor.SelectedIndex = 0;
                        cbHDDColor.Enabled = false;
                    }
                    else
                    {
                        //Check Product
                        bChild = false;
                        List<string> lsHddProduct = hcl.GetListProductByManuAndMemoryAndStandardAndRound(cbHDDManufacture.Text, cbHDDMemory.Text, cbHDDStandard.Text, cbHDDRound.Text);

                        if (cbHDDProduct.Enabled && cbHDDProduct.SelectedIndex > 0)
                        {
                            if (lsHddProduct.Contains(cbHDDProduct.Text))
                            {
                                bChild = true;
                            }
                        }

                        if (!bChild)
                        {
                            cbHDDProduct.Enabled = true;
                            cbHDDProduct.Items.Clear();
                            cbHDDProduct.Items.Add("- Chọn Sản Phẩm -");
                            foreach (string str in lsHddProduct)
                            {
                                cbHDDProduct.Items.Add(str);
                            }
                            cbHDDColor.SelectedIndex = 0;
                            cbHDDColor.Enabled = false;

                        }
                        else
                        {
                            bChild = false;
                            HinhAnhController hacl = new HinhAnhController();
                            List<string> lstColor = hacl.GetListColorByProName(cbHDDProduct.Text);
                            if (cbHDDColor.Enabled && cbHDDColor.SelectedIndex > 0)
                            {
                                if (lstColor.Contains(cbHDDColor.Text))
                                {
                                    bChild = true;
                                }
                            }
                            if (!bChild)
                            {
                                cbHDDColor.Enabled = true;
                                cbHDDColor.Items.Clear();
                                cbHDDColor.Items.Add("- Chọn Màu Sắc -");
                                foreach (string str in lstColor)
                                {
                                    cbHDDColor.Items.Add(str);
                                }
                            }
                            else
                            {

                                //Load San pham
                                ProductController pcl = new ProductController();
                                ProductTypeController ptcl = new ProductTypeController();
                                int iCateID = ptcl.GetProductTypeIDByName("HDD");
                                int iHDDID = hcl.GetHDDIdByManuAndMemoryAndStandardAndRoundAndName(cbHDDManufacture.Text, cbHDDMemory.Text, cbHDDStandard.Text, cbHDDRound.Text, cbHDDProduct.Text);
                                DataTable dt;
                                ProductInfo pInfo = pcl.getProductDetail(iHDDID.ToString(), iCateID.ToString(), out dt);
                                HyperLink imgHdd = new HyperLink();
                                imgHdd.ImageUrl = pInfo.Hinh_Anh.URL;
                                imgHdd.NavigateUrl = "~/Products/detail.aspx?ProductId=" + iHDDID.ToString() + "&CategoryId=" + iCateID.ToString();
                                tbimgHDD.Cells[1].Controls.Add(imgHdd);
                                lbHDDPrice.Text = Utilities.ConvertToMoneyFormat(pInfo.Gia, true);
                                UpdateTotalPrice();


                            }
                        }
                    }
                }
            }
        }
        else
        {
            cbHDDProduct.SelectedIndex = 0;
            cbHDDProduct.Enabled = false;
            cbHDDMemory.SelectedIndex = 0;
            cbHDDMemory.Enabled = false;
            cbHDDStandard.SelectedIndex = 0;
            cbHDDStandard.Enabled = false;
            cbHDDRound.SelectedIndex = 0;
            cbHDDRound.Enabled = false;
            cbHDDColor.SelectedIndex = 0;
            cbHDDColor.Enabled = false;

        }
        
    }

    private void CDPostBackProcessing()
    {
        bool bChild = false;
        lbCDPrice.Text = "";
        if (tbimgCD.Cells[1].Controls.Count > 0)
        {
            tbimgCD.Cells[1].Controls.RemoveAt(0);
        }
        if (cbCDManufacture.SelectedIndex > 0)
        {
            bChild = false;
            CDController ccl = new CDController();
            List<string> lst = ccl.GetListSpeedByManufactureName(cbCDManufacture.Text);
            if (cbCDSpeed.Enabled && cbCDSpeed.SelectedIndex > 0)
            {
                if (lst.Contains(cbCDSpeed.Text))
                {
                    bChild = true;

                }
            }

            if (!bChild)
            {
                cbCDSpeed.Enabled = true;
                cbCDSpeed.Items.Clear();
                cbCDSpeed.Items.Add("- Chọn Tốc Độ -");
                foreach (string str in lst)
                {
                    cbCDSpeed.Items.Add(str);
                }
                cbCDProduct.SelectedIndex = 0;
                cbCDProduct.Enabled = false;
                cbCDColor.SelectedIndex = 0;
                cbCDColor.Enabled = false;
            }
            else
            {

                bChild = false;

                List<string> lstPro = ccl.GetListProductNameByManuAndSpeed(cbCDManufacture.Text, cbCDSpeed.Text);
                if (cbCDProduct.Enabled && cbCDProduct.SelectedIndex > 0)
                {
                    if (lstPro.Contains(cbCDProduct.Text))
                    {
                        bChild = true;

                    }
                }

                if (!bChild)
                {
                    cbCDProduct.Enabled = true;
                    cbCDProduct.Items.Clear();
                    cbCDProduct.Items.Add("- Chọn Sản Phẩm-");
                    foreach (string str in lstPro)
                    {
                        cbCDProduct.Items.Add(str);
                    }
                    cbCDColor.SelectedIndex = 0;
                    cbCDColor.Enabled = false;
                }
                else
                {

                    bChild = false;
                    HinhAnhController hacl = new HinhAnhController();
                    List<string> lstColor = hacl.GetListColorByProName(cbCDProduct.Text);
                    if (cbCDColor.Enabled && cbCDColor.SelectedIndex > 0)
                    {
                        if (lstColor.Contains(cbCDColor.Text))
                        {
                            bChild = true;
                        }
                    }
                    if (!bChild)
                    {
                        cbCDColor.Enabled = true;
                        cbCDColor.Items.Clear();
                        cbCDColor.Items.Add("- Chọn Màu Sắc -");
                        foreach (string str in lstColor)
                        {
                            cbCDColor.Items.Add(str);
                        }
                    }
                    else
                    {
                        ProductTypeController ptcl = new ProductTypeController();
                        int iCateID = ptcl.GetProductTypeIDByName("CD_DVD");
                        int iCDID = ccl.GetCDIDByManuAndSpeedAndName(cbCDManufacture.Text, cbCDSpeed.Text, cbCDProduct.Text);
                        ProductController pcl = new ProductController();
                        DataTable dt;
                        ProductInfo pInfo = pcl.getProductDetail(iCDID.ToString(), iCateID.ToString(), out dt);
                        HyperLink imgCD = new HyperLink();
                        imgCD.ImageUrl = pInfo.Hinh_Anh.URL;
                        imgCD.NavigateUrl = "~/Products/detail.aspx?ProductId=" + iCDID.ToString() + "&CategoryId=" + iCateID.ToString();
                        tbimgCD.Cells[1].Controls.Add(imgCD);
                        lbCDPrice.Text = Utilities.ConvertToMoneyFormat(pInfo.Gia, true);
                        UpdateTotalPrice();
                    }
                }
            }
        }
        else
        {
            cbCDSpeed.SelectedIndex = 0;
            cbCDSpeed.Enabled = false;
            cbCDProduct.SelectedIndex = 0;
            cbCDProduct.Enabled = false;
            cbCDColor.SelectedIndex = 0;
            cbCDColor.Enabled = false;
        }
    }

    private void CasePostBackProcessing()
    {
        bool bChild = false;
        lbCasePrice.Text = "";
        if(tbimgCase.Cells[1].Controls.Count > 0)
        {
            tbimgCase.Cells[1].Controls.RemoveAt(0);
        }
        if(cbCASEManufacture.SelectedIndex > 0)
        {
            bChild = false;
            CaseController ccl = new CaseController();
            List<string> lstPro = ccl.GetListProductByManufactureName(cbCASEManufacture.Text);
            if(cbCASEProduct.Enabled && cbCASEProduct.SelectedIndex > 0)
            {
                if(lstPro.Contains(cbCASEProduct.Text))
                {
                    bChild = true;
                    
                }
            }

            if (!bChild)
            {
                cbCASEProduct.Enabled = true;
                cbCASEProduct.Items.Clear();
                cbCASEProduct.Items.Add("- Chọn Sản Phẩm -");
                foreach (string str in lstPro)
                {
                    cbCASEProduct.Items.Add(str);
                }
                cbCaseColor.SelectedIndex = 0;
                cbCaseColor.Enabled = false;
            }
            else
            {
                bChild = false;
                HinhAnhController hacl = new HinhAnhController();
                List<string> lstColor = hacl.GetListColorByProName(cbCASEProduct.Text);
                if (cbCaseColor.Enabled && cbCaseColor.SelectedIndex > 0)
                {
                    if (lstColor.Contains(cbCaseColor.Text))
                    {
                        bChild = true;
                    }
                }
                if (!bChild)
                {
                    cbCaseColor.Enabled = true;
                    cbCaseColor.Items.Clear();
                    cbCaseColor.Items.Add("- Chọn Màu Sắc -");
                    foreach (string str in lstColor)
                    {
                        cbCaseColor.Items.Add(str);
                    }
                }
                else
                {
                    ProductTypeController ptcl = new ProductTypeController();
                    int iCateID = ptcl.GetProductTypeIDByName("CASE");
                    int iCASEID = ccl.GetProIDByManuAndProName(cbCASEManufacture.Text, cbCASEProduct.Text);
                    ProductController pcl = new ProductController();
                    DataTable dt;
                    ProductInfo pInfo = pcl.getProductDetail(iCASEID.ToString(), iCateID.ToString(), out dt);
                    HyperLink imgCase = new HyperLink();
                    imgCase.ImageUrl = pInfo.Hinh_Anh.URL;
                    imgCase.NavigateUrl = "~/Products/detail.aspx?ProductId=" + iCASEID.ToString() + "&CategoryId=" + iCateID.ToString();
                    tbimgCase.Cells[1].Controls.Add(imgCase);
                    lbCasePrice.Text = Utilities.ConvertToMoneyFormat(pInfo.Gia, true);
                    UpdateTotalPrice();
                }

            }
        }
        else
        {
            cbCASEProduct.SelectedIndex = 0;
            cbCASEProduct.Enabled = false;
            cbCaseColor.SelectedIndex = 0;
            cbCaseColor.Enabled = false;
        }
    }

    private void PowerPostBackProcessing()
    {
        bool bChild = false;
        lbPowerPrice.Text = "";
        if (tbimgPower.Cells[1].Controls.Count > 0)
        {
            tbimgPower.Cells[1].Controls.RemoveAt(0);
        }
        if (cbPOWERManufacture.SelectedIndex > 0)
        {
            bChild = false;
            PowerController ccl = new PowerController();
            List<string> lstPro = ccl.GetListProductByManufactureName(cbPOWERManufacture.Text);
            if (cbPOWERProduct.Enabled && cbPOWERProduct.SelectedIndex > 0)
            {
                if (lstPro.Contains(cbPOWERProduct.Text))
                {
                    bChild = true;

                }
            }

            if (!bChild)
            {
                cbPOWERProduct.Enabled = true;
                cbPOWERProduct.Items.Clear();
                cbPOWERProduct.Items.Add("- Chọn Sản Phẩm -");
                foreach (string str in lstPro)
                {
                    cbPOWERProduct.Items.Add(str);
                }
                cbPowerColor.SelectedIndex = 0;
                cbPowerColor.Enabled = false;
            }
            else
            {
                bChild = false;
                HinhAnhController hacl = new HinhAnhController();
                List<string> lstColor = hacl.GetListColorByProName(cbPOWERProduct.Text);
                if (cbPowerColor.Enabled && cbPowerColor.SelectedIndex > 0)
                {
                    if (lstColor.Contains(cbPowerColor.Text))
                    {
                        bChild = true;
                    }
                }
                if (!bChild)
                {
                    cbPowerColor.Enabled = true;
                    cbPowerColor.Items.Clear();
                    cbPowerColor.Items.Add("- Chọn Màu Sắc -");
                    foreach (string str in lstColor)
                    {
                        cbPowerColor.Items.Add(str);
                    }
                }
                else
                {
                    ProductTypeController ptcl = new ProductTypeController();
                    int iCateID = ptcl.GetProductTypeIDByName("CASE");
                    int iPowerID = ccl.GetProIDByManuAndProName(cbPOWERManufacture.Text, cbPOWERProduct.Text);
                    ProductController pcl = new ProductController();
                    DataTable dt;
                    ProductInfo pInfo = pcl.getProductDetail(iPowerID.ToString(), iCateID.ToString(), out dt);
                    HyperLink imgPower = new HyperLink();
                    imgPower.ImageUrl = pInfo.Hinh_Anh.URL;
                    imgPower.NavigateUrl = "~/Products/detail.aspx?ProductId=" + iPowerID.ToString() + "&CategoryId=" + iCateID.ToString();
                    tbimgPower.Cells[1].Controls.Add(imgPower);
                    lbPowerPrice.Text = Utilities.ConvertToMoneyFormat(pInfo.Gia, true);
                    UpdateTotalPrice();
                }
            }

        }
        else
        {
            cbPOWERProduct.SelectedIndex = 0;
            cbPOWERProduct.Enabled = false;
            cbPowerColor.SelectedIndex = 0;
            cbPowerColor.Enabled = false;
        }
    }

    private void SoundCardPostBackProcessing()
    {
        bool bChild = false;
        lbSoundCardPrice.Text = "";
        if (tbimgSoundCard.Cells[1].Controls.Count > 0)
        {
            tbimgSoundCard.Cells[1].Controls.RemoveAt(0);
        }
        if (cbSOUNDCARDManufacture.SelectedIndex > 0)
        {
            bChild = false;
            SoundCardController ccl = new SoundCardController();
            List<string> lstPro = ccl.GetListProductByManufactureName(cbSOUNDCARDManufacture.Text);
            if (cbSOUNDCARDProduct.Enabled && cbSOUNDCARDProduct.SelectedIndex > 0)
            {
                if (lstPro.Contains(cbSOUNDCARDProduct.Text))
                {
                    bChild = true;
                }
            }

            if (!bChild)
            {
                cbSOUNDCARDProduct.Enabled = true;
                cbSOUNDCARDProduct.Items.Clear();
                cbSOUNDCARDProduct.Items.Add("- Chọn Sản Phẩm -");
                foreach (string str in lstPro)
                {
                    cbSOUNDCARDProduct.Items.Add(str);
                }
                cbSoundCardColor.SelectedIndex = 0;
                cbSoundCardColor.Enabled = false;
            }
            else
            {
                bChild = false;
                HinhAnhController hacl = new HinhAnhController();
                List<string> lstColor = hacl.GetListColorByProName(cbSOUNDCARDProduct.Text);
                if (cbSoundCardColor.Enabled && cbSoundCardColor.SelectedIndex > 0)
                {
                    if (lstColor.Contains(cbSoundCardColor.Text))
                    {
                        bChild = true;
                    }
                }
                if (!bChild)
                {
                    cbSoundCardColor.Enabled = true;
                    cbSoundCardColor.Items.Clear();
                    cbSoundCardColor.Items.Add("- Chọn Màu Sắc -");
                    foreach (string str in lstColor)
                    {
                        cbSoundCardColor.Items.Add(str);
                    }
                }
                else
                {
                    ProductTypeController ptcl = new ProductTypeController();
                    int iCateID = ptcl.GetProductTypeIDByName("SOUNDCARD");
                    int iSoundCardID = ccl.GetProIDByManuAndProName(cbSOUNDCARDManufacture.Text, cbSOUNDCARDProduct.Text);
                    ProductController pcl = new ProductController();
                    DataTable dt;
                    ProductInfo pInfo = pcl.getProductDetail(iSoundCardID.ToString(), iCateID.ToString(), out dt);
                    HyperLink imgSoundCard = new HyperLink();
                    imgSoundCard.ImageUrl = pInfo.Hinh_Anh.URL;
                    imgSoundCard.NavigateUrl = "~/Products/detail.aspx?ProductId=" + iSoundCardID.ToString() + "&CategoryId=" + iCateID.ToString();
                    tbimgSoundCard.Cells[1].Controls.Add(imgSoundCard);
                    lbSoundCardPrice.Text = Utilities.ConvertToMoneyFormat(pInfo.Gia, true);
                    UpdateTotalPrice();
                }
            }
        }
        else
        {
            cbSOUNDCARDProduct.SelectedIndex = 0;
            cbSOUNDCARDProduct.Enabled = false;
            cbSoundCardColor.SelectedIndex = 0;
            cbSoundCardColor.Enabled = false;
        }
    }

    private void VGAPostBackProcessing()
    {
        bool bChild = false;
        lbVGAPrice.Text = "";
        if (tbimgVGA.Cells[1].Controls.Count > 0)
        {
            tbimgVGA.Cells[1].Controls.RemoveAt(0);
        }
        if (cbVGAManufacture.SelectedIndex > 0)
        {
            bChild = false;
            VGAController vcl = new VGAController();
            List<string> lstEngine = vcl.GetListEngineByManufacture(cbVGAManufacture.Text);
            if (cbVGAEngine.Enabled && cbVGAEngine.SelectedIndex > 0)
            {
                if (lstEngine.Contains(cbVGAEngine.Text))
                {
                    bChild = true;
                }
            }

            if (!bChild)
            {
                cbVGAEngine.Enabled = true;
                cbVGAEngine.Items.Clear();
                cbVGAEngine.Items.Add("- Chọn Sản Phẩm -");
                foreach (string str in lstEngine)
                {
                    cbVGAEngine.Items.Add(str);
                }
                cbVGAMemory.SelectedIndex = 0;
                cbVGAMemory.Enabled = false;
                cbVGAProduct.SelectedIndex = 0;
                cbVGAProduct.Enabled = false;
                cbVGAColor.SelectedIndex = 0;
                cbVGAColor.Enabled = false;
            }
            else
            {
                bChild = false;

                List<string> lstMemory = vcl.GetListMemoryByManufactureAndEngine(cbVGAManufacture.Text, cbVGAEngine.Text);
                if (cbVGAMemory.Enabled && cbVGAMemory.SelectedIndex > 0)
                {
                    if (lstMemory.Contains(cbVGAMemory.Text))
                    {
                        bChild = true;
                    }
                }

                if (!bChild)
                {
                    cbVGAMemory.Enabled = true;
                    cbVGAMemory.Items.Clear();
                    cbVGAMemory.Items.Add("- Chọn Sản Phẩm -");
                    foreach (string str in lstMemory)
                    {
                        cbVGAMemory.Items.Add(str);
                    }
                    cbVGAProduct.SelectedIndex = 0;
                    cbVGAProduct.Enabled = false;
                    cbVGAColor.SelectedIndex = 0;
                    cbVGAColor.Enabled = false;
                }
                else
                {
                    bChild = false;

                    List<string> lstPro = vcl.GetListProductByManufactureAndEngineAndMemory(cbVGAManufacture.Text, cbVGAEngine.Text, cbVGAMemory.Text);
                    if (cbVGAProduct.Enabled && cbVGAProduct.SelectedIndex > 0)
                    {
                        if (lstPro.Contains(cbVGAProduct.Text))
                        {
                            bChild = true;
                        }
                    }

                    if (!bChild)
                    {
                        cbVGAProduct.Enabled = true;
                        cbVGAProduct.Items.Clear();
                        cbVGAProduct.Items.Add("- Chọn Sản Phẩm -");
                        foreach (string str in lstPro)
                        {
                            cbVGAProduct.Items.Add(str);
                        }
                        cbVGAColor.SelectedIndex = 0;
                        cbVGAColor.Enabled = false;
                    }
                    else
                    {
                        bChild = false;
                        HinhAnhController hacl = new HinhAnhController();
                        List<string> lstColor = hacl.GetListColorByProName(cbVGAProduct.Text);
                        if (cbVGAColor.Enabled && cbVGAColor.SelectedIndex > 0)
                        {
                            if (lstColor.Contains(cbVGAColor.Text))
                            {
                                bChild = true;
                            }
                        }
                        if (!bChild)
                        {
                            cbVGAColor.Enabled = true;
                            cbVGAColor.Items.Clear();
                            cbVGAColor.Items.Add("- Chọn Màu Sắc -");
                            foreach (string str in lstColor)
                            {
                                cbVGAColor.Items.Add(str);
                            }
                        }
                        else
                        {
                            ProductTypeController ptcl = new ProductTypeController();
                            int iCateID = ptcl.GetProductTypeIDByName("VGA");
                            int iVGAID = vcl.GetVGAIDByManufactureAndEngineAndMemoryAndName(cbVGAManufacture.Text, cbVGAEngine.Text, cbVGAMemory.Text, cbVGAProduct.Text);
                            ProductController pcl = new ProductController();
                            DataTable dt;
                            ProductInfo pInfo = pcl.getProductDetail(iVGAID.ToString(), iCateID.ToString(), out dt);
                            HyperLink imgVGA = new HyperLink();
                            imgVGA.ImageUrl = pInfo.Hinh_Anh.URL;
                            imgVGA.NavigateUrl = "~/Products/detail.aspx?ProductId=" + iVGAID.ToString() + "&CategoryId=" + iCateID.ToString();
                            tbimgVGA.Cells[1].Controls.Add(imgVGA);
                            lbVGAPrice.Text = Utilities.ConvertToMoneyFormat(pInfo.Gia, true);
                            UpdateTotalPrice();
                        }
                    }
                }
            }
        }
        else
        {
            cbVGAEngine.SelectedIndex = 0;
            cbVGAEngine.Enabled = false;
            cbVGAMemory.SelectedIndex = 0;
            cbVGAMemory.Enabled = false;
            cbVGAProduct.SelectedIndex = 0;
            cbVGAProduct.Enabled = false;
            cbVGAColor.SelectedIndex = 0;
            cbVGAColor.Enabled = false;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        if(IsPostBack)
        {
            lbTotalPrice.Text = "";
            btnAddToCart.PostBackUrl = "";
            MainBoardPostBackProcessing();
            CPUPostBackProcessing();
            RamPostBackProcessing();
            CDPostBackProcessing();
            HDDPostBackProcessing();
            CasePostBackProcessing();
            PowerPostBackProcessing();
            SoundCardPostBackProcessing();
            VGAPostBackProcessing();
        }
        else
        {
            ProductTypeController pcl = new ProductTypeController();

            //Main
            int iMainBoardID = pcl.GetProductTypeIDByName("MAINBOARD");

            ManufactureController mcl = new ManufactureController();
            List<string> lstManuMain = mcl.GetManuFactureNameByCatelogyID(iMainBoardID);
            cbMainManufacture.Items.Clear();
            cbMainManufacture.Items.Add("- Chọn nhà sản xuất -");
            foreach (string str in lstManuMain)
            {
                cbMainManufacture.Items.Add(str);
            }
            cbMainProduct.Items.Add("- Chọn sản phẩm -");
            cbMainProduct.Enabled = false;

            //CPu
            int iCPUCatelogyID = pcl.GetProductTypeIDByName("CPU");
            List<string> lstManuCPU = mcl.GetManuFactureNameByCatelogyID(iCPUCatelogyID);
            cbCPUManufacture.Items.Clear();
            cbCPUManufacture.Items.Add("- Chọn nhà sản xuất -");
            foreach (string str in lstManuCPU)
            {
                cbCPUManufacture.Items.Add(str);
            }
            cbCPUSocket.Items.Clear();
            cbCPUSocket.Items.Add("- Chọn Socket -");
            cbCPUBus.Items.Clear();
            cbCPUBus.Items.Add("- Chọn Bus -");
            cbCPUSpeed.Items.Clear();
            cbCPUSpeed.Items.Add("- Chọn Tốc Độ -");
            cbCPUProduct.Items.Clear();
            cbCPUProduct.Items.Add("- Chọn Sản Phẩm -");
            cbCPUSocket.Enabled = false;
            cbCPUBus.Enabled = false;
            cbCPUSpeed.Enabled = false;
            cbCPUProduct.Enabled = false;
            
            //Ram
            int iRamCatelogyID = pcl.GetProductTypeIDByName("RAM");
            List<string> lstManuRam = mcl.GetManuFactureNameByCatelogyID(iRamCatelogyID);
            cbRAMManufacture.Items.Clear();
            cbRAMManufacture.Items.Add("- Chọn nhà sản xuất -");
            foreach (string str in lstManuRam)
            {
                cbRAMManufacture.Items.Add(str);
            }
            cbRAMMemory.Items.Clear();
            cbRAMMemory.Items.Add("- Chọn Dung Lượng -");
            cbRAMBus.Items.Clear();
            cbRAMBus.Items.Add("- Chọn Bus -");      
            cbRAMProduct.Items.Clear();
            cbRAMProduct.Items.Add("- Chọn Sản Phẩm -");
            cbRAMMemory.Enabled = false;
            cbRAMBus.Enabled = false;
            cbRAMProduct.Enabled = false;


            //HDD
            int iHDDCatelogyID = pcl.GetProductTypeIDByName("HDD");
            List<string> lstManuHDD = mcl.GetManuFactureNameByCatelogyID(iHDDCatelogyID);
            cbHDDManufacture.Items.Clear();
            cbHDDManufacture.Items.Add("- Chọn nhà sản xuất -");
            foreach (string str in lstManuHDD)
            {
                cbHDDManufacture.Items.Add(str);
            }
            cbHDDMemory.Items.Clear();
            cbHDDMemory.Items.Add("- Chọn Dung Lượng -");
            cbHDDStandard.Items.Clear();
            cbHDDStandard.Items.Add("- Chọn Chuẩn -");
            cbHDDRound.Items.Clear();
            cbHDDRound.Items.Add("- Chọn Số Vòng -");
            cbHDDProduct.Items.Clear();
            cbHDDProduct.Items.Add("- Chọn Sản Phẩm -");
            cbHDDMemory.Enabled = false;
            cbHDDStandard.Enabled = false;
            cbHDDProduct.Enabled = false;
            cbHDDRound.Enabled = false;


            //CD_DVD
            int iCDCatelogyID = pcl.GetProductTypeIDByName("CD_DVD");
            List<string> lstManuCD = mcl.GetManuFactureNameByCatelogyID(iCDCatelogyID);
            cbCDManufacture.Items.Clear();
            cbCDManufacture.Items.Add("- Chọn nhà sản xuất -");
            foreach (string str in lstManuCD)
            {
                cbCDManufacture.Items.Add(str);
            }
            cbCDSpeed.Items.Clear();
            cbCDSpeed.Items.Add("- Chọn Tốc Đô -");           
            cbCDProduct.Items.Clear();
            cbCDProduct.Items.Add("- Chọn Sản Phẩm -");
            cbCDSpeed.Enabled = false;
            cbCDProduct.Enabled = false;

            //CASE
            int iCaseCatelogyID = pcl.GetProductTypeIDByName("CASE");
            List<string> lstManuCase = mcl.GetManuFactureNameByCatelogyID(iCaseCatelogyID);
            cbCASEManufacture.Items.Clear();
            cbCASEManufacture.Items.Add("- Chọn nhà sản xuất -");
            foreach (string str in lstManuCase)
            {
                cbCASEManufacture.Items.Add(str);
            }
            cbCASEProduct.Items.Clear();
            cbCASEProduct.Items.Add("- Chọn Sản Phẩm -");
            cbCASEProduct.Enabled = false;

            //Power
            int iPOWERCatelogyID = pcl.GetProductTypeIDByName("POWER");
            List<string> lstManuPower = mcl.GetManuFactureNameByCatelogyID(iPOWERCatelogyID);
            cbPOWERManufacture.Items.Clear();
            cbPOWERManufacture.Items.Add("- Chọn nhà sản xuất -");
            foreach (string str in lstManuPower)
            {
                cbPOWERManufacture.Items.Add(str);
            }
            cbPOWERProduct.Items.Clear();
            cbPOWERProduct.Items.Add("- Chọn Sản Phẩm -");
            cbPOWERProduct.Enabled = false;

            //Sound Card
            int iSOUNDCARDCatelogyID = pcl.GetProductTypeIDByName("SOUNDCARD");
            List<string> lstManuSoundCard = mcl.GetManuFactureNameByCatelogyID(iSOUNDCARDCatelogyID);
            cbSOUNDCARDManufacture.Items.Clear();
            cbSOUNDCARDManufacture.Items.Add("- Chọn nhà sản xuất -");
            foreach (string str in lstManuSoundCard)
            {
                cbSOUNDCARDManufacture.Items.Add(str);
            }
            cbSOUNDCARDProduct.Items.Clear();
            cbSOUNDCARDProduct.Items.Add("- Chọn Sản Phẩm -");
            cbSOUNDCARDProduct.Enabled = false;


            //VGA
            int iVGACatelogyID = pcl.GetProductTypeIDByName("VGA");
            List<string> lstManuVGA= mcl.GetManuFactureNameByCatelogyID(iVGACatelogyID);
            cbVGAManufacture.Items.Clear();
            cbVGAManufacture.Items.Add("- Chọn nhà sản xuất -");
            foreach (string str in lstManuVGA)
            {
                cbVGAManufacture.Items.Add(str);
            }
            cbVGAProduct.Items.Clear();
            cbVGAProduct.Items.Add("- Chọn Sản Phẩm -");
            cbVGAEngine.Items.Clear();
            cbVGAEngine.Items.Add("- Chọn Engine -");
            cbVGAMemory.Items.Clear();
            cbVGAMemory.Items.Add("- Chọn Dung Lượng -");
            cbVGAProduct.Enabled = false;
            cbVGAEngine.Enabled = false;
            cbVGAMemory.Enabled = false;


            cbMainColor.Items.Clear();
            cbMainColor.Items.Add("- Chọn Màu Sắc -");
            cbCPUColor.Items.Clear();
            cbCPUColor.Items.Add("- Chọn Màu Sắc -");
            cbRAMColor.Items.Clear();
            cbRAMColor.Items.Add("- Chọn Màu Sắc -");
            cbHDDColor.Items.Clear();
            cbHDDColor.Items.Add("- Chọn Màu Sắc -");
            cbCDColor.Items.Clear();
            cbCDColor.Items.Add("- Chọn Màu Sắc -");
            cbCaseColor.Items.Clear();
            cbCaseColor.Items.Add("- Chọn Màu Sắc -");
            cbPowerColor.Items.Clear();
            cbPowerColor.Items.Add("- Chọn Màu Sắc -");
            cbSoundCardColor.Items.Clear();
            cbSoundCardColor.Items.Add("- Chọn Màu Sắc -");
            cbVGAColor.Items.Clear();
            cbVGAColor.Items.Add("- Chọn Màu Sắc -");

            cbMainColor.Enabled = false;
            cbCPUColor.Enabled = false;
            cbRAMColor.Enabled = false;
            cbHDDColor.Enabled = false;
            cbCDColor.Enabled = false;
            cbSoundCardColor.Enabled = false;
            cbVGAColor.Enabled = false;
            cbCaseColor.Enabled = false;
            cbPowerColor.Enabled = false;


            //HinhAnhController hcl = new HinhAnhController();
            //List<string> strcolor = hcl.GetHinhAnhIDByColorNameAndProductName();
            //cbMainColor.Items.Clear();
            //cbPowerColor.Items.Clear();
            //cbCaseColor.Items.Clear();
            //cbCDColor.Items.Clear();
            //cbPowerColor.Items.Add("Đen");
            //cbPowerColor.Items.Add("Trắng");

            //cbCDColor.Items.Add("Đen");
            //cbCDColor.Items.Add("Trắng");
            //foreach (string str in strcolor)
            //{
            //    cbMainColor.Items.Add(str);
            //    cbCaseColor.Items.Add(str);
            //}


            string sProID = Request.QueryString["ProID"];
            if(sProID != null)
            {
                int iID;
                if (!int.TryParse(sProID, out iID))
                    return;
                ProductController prcl = new ProductController();
                ProductInfo pInfo = prcl.getProductById(iID);
                string sCatelogy = pInfo.Loai_San_Pham.TenLoaiSanPham;
                switch(sCatelogy)
                {
                    case "MAINBOARD":
                        MainSelectProduct(pInfo);
                        
                        break;
                    case "CPU":
                        CPUSelectProduct(pInfo);
                        break;
                }

            }
        }
    }
    private void MainSelectProduct(ProductInfo pInfo)
    {
        ProductController pcl = new ProductController();
        List<string> strPro = pcl.GetListProductNameByManufactureNameAndCatelogyName(pInfo.NSX.TenNSX, pInfo.Loai_San_Pham.TenLoaiSanPham);
        cbMainManufacture.SelectedValue = pInfo.NSX.TenNSX;
        cbMainProduct.Enabled = true;
        cbMainProduct.Items.Clear();
        cbMainProduct.Items.Add("- Chọn Sản Phẩm -");
        foreach (string  str in strPro)
        {
            cbMainProduct.Items.Add(str);
        }
        cbMainProduct.SelectedValue = pInfo.TenSanPham;

        HinhAnhController hcl = new HinhAnhController();
        List<string> lsColor = hcl.GetListColorByProName(pInfo.TenSanPham);
        cbMainColor.Enabled = true;
        cbMainColor.Items.Clear();
        cbMainColor.Items.Add("- Chọn Màu -");
        foreach (string str in lsColor)
        {
            cbMainColor.Items.Add(str);
        }
        if(cbMainColor.Items.Count > 0)
            cbMainColor.SelectedIndex = 1;

        ProductTypeController ptcl = new ProductTypeController();
        int iMainCatelogyID = ptcl.GetProductTypeIDByName("MAINBOARD");
        int iMainProId = pcl.GetProductIdByProductNameAndCatelogyAndManufacture(cbMainProduct.Text, cbMainManufacture.Text, "MAINBOARD");
        DataTable dtMain;
        //ProductInfo pMainInfo = pcl.getProductById(iMainProId);
        ProductInfo pMainInfoDetail = pcl.getProductDetail(iMainProId.ToString(), "MAINBOARD", out dtMain);
        HyperLink imgMainboard = new HyperLink();
        imgMainboard.ImageUrl = pMainInfoDetail.Hinh_Anh.URL;
        imgMainboard.NavigateUrl = "~/Products/detail.aspx?ProductId=" + iMainProId.ToString() + "&CategoryId=" + iMainCatelogyID.ToString();
        tbMainImageRow.Cells[1].Controls.Add(imgMainboard);
        lbMainPrice.Text = Utilities.ConvertToMoneyFormat(pMainInfoDetail.Gia, true);
        UpdateTotalPrice();
    }
     private void CPUSelectProduct(ProductInfo pInfo)
     {
         //cbCPUManufacture.SelectedValue = pInfo.NSX.TenNSX;
         //CPUController ccl = new CPUController();
         //List<string> lstSocket = ccl.GetListSocketByManufactureName(pInfo.NSX.TenNSX);
         //cbCPUSocket.Enabled = true;
         //cbCPUSocket.Items.Clear();
         //cbCPUSocket.Items.Add("- Chọn Socket -");
         //foreach (string str in lstSocket)
         //{
         //    cbCPUSocket.Items.Add(str);
         //}
         
     }
}
